package com.fengwk.cv4j.ind;

import org.junit.Test;
import org.nd4j.linalg.factory.Nd4j;

import com.fengwk.cv4j.factory.ind.INDViewFactory;
import com.fengwk.cv4j.view.View;
import com.fengwk.cv4j.view.ind.INDArrayWrap;

public class Max {
    
    @Test
    public void test() {
        INDViewFactory f = new INDViewFactory();
        View<INDArrayWrap> X = f.of(Nd4j.create(new float[][][] {
        	{
	            {1, 0, 3},
	            {4, 5, 6}
        	},
        	{
	            {1, 2, 3},
	            {4, 6, 6}
        	}
        }));
        
        View<INDArrayWrap> max_0 = f.max(X, 0);
        View<INDArrayWrap> max_1 = f.max(X, 1);
        View<INDArrayWrap> max_0_1 = f.max(X, 1, 0);
        View<INDArrayWrap> max_1_0 = f.max(X, 0, 1);
        
        System.out.println("------max_0------");
        System.out.println(max_0.compute().arr());
        System.out.println("------max_1------");
        System.out.println(max_1.compute().arr());
        System.out.println("------max_0_1------");
        System.out.println(max_0_1.compute().arr());
        System.out.println("------max_1_0------");
        System.out.println(max_1_0.compute().arr());
        
        System.out.println("------d_max_0------");
        System.out.println(max_0.gradient(X).compute().arr());
        System.out.println("------d_max_1------");
        System.out.println(max_1.gradient(X).compute().arr());
        System.out.println("------d_max_0_1------");
        System.out.println(max_0_1.gradient(X).compute().arr());
        System.out.println("------d_max_1_0------");
        System.out.println(max_1_0.gradient(X).compute().arr());
    }
    
}
